<script src="/validation/jquery.validate.min.js"></script>
<script src="/validation/messages_zh.js"></script>

<script>

    /*
     *  验证器
     */

    $.validator.setDefaults({
        submitHandler: function() {
            roleSubmit();
        }
    });
    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        // var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        // return this.optional(element) || (length == 11 && mobile.test(value));
        return this.optional(element) || (length == 11 );
    }, "请正确填写手机号码");
    jQuery.validator.addMethod("select", function(value, element) {
        return value != "0";
    }, "必须选择一项");
    jQuery.validator.addMethod("notEqualTo", function(value) {
        return value != $("[name='password']").val();
    }, "新密码不能和原密码一致");
    $().ready(function() {
        $('[form="submit"]').validate({

            rules: {
                //设备号
                imel: {required: true},

                //账号、用户名
                user_name: {required: true,minlength: 2},
                //密码
                password:{required: true,},
                //确认密码（注册）
                password2:{required: true,equalTo:"[name='password']"},
                //新密码
                newpassword:{required: true,minlength: 6,notEqualTo:"password"},
                //确认密码（更改密码）
                newpassword2:{required: true,equalTo:"[name='newpassword']"},
                //电子邮箱
                email:{ email: true,},
                //角色名称
                role_name:{required: true, minlength: 2},
                //会员昵称
                nickname:{required: true},
                //手机号
                mobile:{required: true, isMobile :true},
                phone:{required: true, isMobile :true},
                //验证码
                code:{required: true},
                //consignee收货人姓名
                consignee:{required: true} ,
                //province 省
                province:{required: true} ,
                // city 市
                city:{required: true} ,
                name:{ required:true,},
                //district 县、区
                district:{required: true},
                //address 详细地址
                address:{required: true},
                //zipcode 邮政编码
                zipcode:{required: true},
                //remark 提现备注
                remark:{required: true},
                //note 操作备注
                note:{required: true},
                //invoice_no 配送单号
                invoice_no:{required: true},

                //goods_name 商品名称
                goods_name:{required: true},
                //goods_remark 商品简介
                goods_remark:{required: true},
                //class 商品分类
                // "class[]":{required: true ,select :true},
                //goods_sn 商品货号
                goods_sn:{required: true},
                //attr[]  商品属性
                // "attr[]":{required: true},
                //type_id 属性类型
                type_id:{required: true,select :true},

                attr_name:{required: true},
                //点卡号
                card_name:{required: true},
                //点卡密码
                card_pass:{required: true},

            },
            messages: {
                user_name: { minlength: "用户名必需由两个或两个以上组成"},

                mobile:{isMobile:"请输入正确格式手机号"},
            }
        });
    });
</script>